<?php
/**
 * File: keywordrelation.php.
 * Author: zhouzhe@haibao.com
 * Editor: PhpStorm
 * Date: 16/8/8 下午2:23
 * Brief:
 */
namespace haibao\cms\business;

use \haibao\cms\data\KeywordRelation as KeywordRelationData;
use haibao\frame\data\query\Condition;

class KeywordRelation extends \haibao\cms\business\Base{
	public static function checkObjectExist($objectType,$objectId){
		$filter = new \haibao\cms\model\filter\KeywordRelation();
		$filter->where($filter::CONDITION_FIELD_NAME_OBJECT_TYPE,Condition::CONDITION_EQUAL,$objectType);
		$filter->where($filter::CONDITION_FIELD_NAME_OBJECT_ID,Condition::CONDITION_EQUAL,$objectId);
		$data = new KeywordRelationData();
		return $data->getOne($filter);
	}

	public static function addObject($model){
		$data = new KeywordRelationData();
		$model->CreateBy = self::getCurrentUser()->Id;
		$data->add($model);
	}

	public static function getAll($filter){
		$data = new KeywordRelationData();
		return $data->getAll($filter);
	}

	public static function getObjectType(){
		return array(
			\haibao\cms\model\data\KeywordRelation::OBJECT_TYPE_ARTICLE => '文章',
			\haibao\cms\model\data\KeywordRelation::OBJECT_TYPE_IMAGE => '图集',
			\haibao\cms\model\data\KeywordRelation::OBJECT_TYPE_VIDEO => '视频',
			\haibao\cms\model\data\KeywordRelation::OBJECT_TYPE_FEATURE => '专题'
		);
	}

	public static function deleteObjectById($id){
		$data = new KeywordRelationData();
		$data->removeById($id);
	}
}